<?php
/**
 * Attributes default values model. If attribute field type is RADIO or SELECT it
 * could has default (predifined) values 
 * 
 * @author Konstantin Shamko <konstantin.shamko@gmail.com> 
 * @version 0.0.1
 * @copyright  Copyright (c) 2009 Konstantin Shamko
 * @package Products Module
 * @license  New BSD License
 *
 */
class Models_ProductAttributes_DefaultValues extends Bel_Model_Abstract {
	
	/**
	 * Describes many-to-one ralation between default values and attributes
	 *
	 * @var array
	 */	
	protected $_referenceMap = array (
								'Attributes' => array (
									'columns' => 'attribute_id',
									'refTableClass' => 'Models_ProductAttributes',
									'refColumns' => 'attribute_id', 
									'onDelete' => self::CASCADE	)
								);
	
	/**
	 * Sets table name and primary key
	 *
	 * @return void
	 */									
	public function __construct() {
		$this->_name = TABLE_PREFIX . "product_attribute_default_values";
		$this->_primary = array('value_id');
		parent::__construct ();
	}
	
	/**
	 * Delete attributes values by attribute ID
	 *
	 * @param integer $attribute_id - product attribute ID
	 */
	public function deleteValuesByAttribute($attribute_id){
		$this->delete('attribute_id=\''.$attribute_id.'\'');
	}
	
	/**
	 * Returns default values for product attribute
	 *
	 * @param integer $attribute_id - product attribute ID
	 * @return Zend_Db_Table_Rowset_Abstract
	 */
	public function getValuesByAttribute($attribute_id){
		return $this->fetchAll('attribute_id='.$attribute_id);
	}
}